package com.message.tcp.ip.application.ui.component;

import java.awt.BorderLayout;
import java.awt.Color;
import java.util.List;

import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.message.tcp.ip.socket.configure.entity.Case;
import com.message.tcp.ip.socket.configure.service.CaseService;

public class IssuerPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JSplitPane splitPane;
	private JScrollPane casesPane;
	private JMenuBar settingBar;
	private JMenu settingMenu;
	private JMenuItem paramItem;
	private JLabel caseLabel;
	private JScrollPane monitorPane;
	private JLabel monitorLabel;
	private JPanel monitor;
	
	/**
	 * Create the panel.
	 */
	@SuppressWarnings("resource")
	public IssuerPanel() {
		setLayout(new BorderLayout(0, 0));
		splitPane = new JSplitPane();
		splitPane.setResizeWeight(0.25);
		add(splitPane, BorderLayout.CENTER);
		
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		CaseService caseService = (CaseService) context.getBean("caseService");
		List<Case> cases = caseService.getIssCases();
		DefaultListModel<String> model = new DefaultListModel<String>();
		for(Case c : cases){
			model.addElement(c.getName());
		}
		JList<String> list = new JList<String>(model);
		casesPane = new JScrollPane(list);
		splitPane.setLeftComponent(casesPane);
		
		caseLabel = new JLabel("Issuer Mode Cases");
		casesPane.setColumnHeaderView(caseLabel);
		
		monitorPane = new JScrollPane();
		splitPane.setRightComponent(monitorPane);
		
		monitorLabel = new JLabel("Mornitor Console");
		monitorPane.setColumnHeaderView(monitorLabel);
		
		monitor = new JPanel();
		monitor.setBackground(Color.WHITE);
		monitorPane.setViewportView(monitor);
		
		settingBar = new JMenuBar();
		add(settingBar, BorderLayout.NORTH);
		
		settingMenu = new JMenu("Setting");
		settingBar.add(settingMenu);
		
		paramItem = new JMenuItem("Parameter");
		settingMenu.add(paramItem);

	}

}
